package leetcode.剑指offer;

import java.util.Stack;

public class 从尾到头打印链表06 {


    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        int size = 0;
        while (head!=null){
            stack.add(head.val);
            size ++;
            head = head.next;
        }
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = stack.pop();
        }
        return res;
    }
}
